<extend name="Public:base"/>

<!--侧边导航-->
<block name="aside">
    <include file="Public:aside"/>
</block>

<block name="main">
    <script type="text/javascript">
        function checknode(obj) {
            var chk = $("input[type='checkbox']");
            var count = chk.length;
            var num = chk.index(obj);
            var level_top = level_bottom =  chk.eq(num).attr('level');

            for (var i=num; i>=0; i--) {
                var le = chk.eq(i).attr('level');
                if(eval(le) < eval(level_top)) {
                    chk.eq(i).attr("checked",true);
                    var level_top = level_top-1;
                }
            }

            for (var j=num+1; j<count; j++){
                var le = chk.eq(j).attr('level');
                if(chk.eq(num).attr("checked")=='checked') {

                    if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked",true);
                    else if(eval(le) == eval(level_bottom)) break;
                }
                else {
                    if(eval(le) > eval(level_bottom)) chk.eq(j).attr("checked",false);
                    else if(eval(le) == eval(level_bottom)) break;
                }
            }
        }
    </script>
    <style>
        .table>thead>tr>th, .table>tbody>tr>th, .table>tfoot>tr>th, .table>thead>tr>td, .table>tbody>tr>td, .table>tfoot>tr>td{
            padding: 0 ;
            line-height: 40px;
        }
        span.w1{
            float:left;
            padding: 0 10px;
            line-height: 40px;
        }
    </style>

    <form id="myform" name="myform" action="{:U('Role/access_edit')}" method="post">
        <input type="hidden" id="rid" name="rid" value="{$rid}" />
        <table class="table access-table" id="dnd-example">
            <tbody>
            <volist name="node" id="r" >
                <tr>
                    <td colspan="2" bgcolor="#F0F5FB" align="center" height="40"><b>{$r[groupinfo][name]}</b></td>
                </tr>
                <volist name="r[data]" id="rr">

                    <if condition="$rr[level]==2">
                        <tr>
                            <td style='padding-left:15px;' bgcolor="#F8FAFC">
                                <input type='checkbox' name='nid[{$rr.id}]' value='{$rr.id}' level='{$rr.level}' {$rr.selected}  onclick='javascript:checknode(this);' />&nbsp;{$rr.title}
                            </td>
                            <td>
                                <volist name="node[$rr[groupid]][data]" id="rrr" >
                                    <if condition="$rrr[pid]==$rr[id]">
                            <span class="w1">
                            <input type='checkbox' name='nid[{$rrr.id}]' value='{$rrr.id}'  level='{$rrr.level}' {$rrr.selected}  onclick='javascript:checknode(this);' /> {$rrr.title} &nbsp;</span>
                                    </if>
                                </volist>
                            </td>

                        </tr>

                    </if>
                </volist>
            </volist>
            </tbody>
        </table>
        <div class="panel-footer">
            <input type='checkbox' name='nid[1]' value='1' level='0' {if array_key_exists(1,$alist)}checked{/if}  onclick='javascript:checknode(this);' />
            <input type="hidden" name="isajax" value="1" />
            <input name="dosubmit" type="submit" value="确认" class="btn btn-primary btn-sm">
        </div>
    </form>
</block>

<block name="script">
    <script type="text/javascript">
        $(document).ready(function() {
            $('#myform').ajaxForm({
                success:  complete,  // post-submit callback
                dataType: 'json'
            });
        });

        function complete(data){
            if (data.status == 1) {
                layer.msg(data.info, {
                    icon: 1,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                }, function(){
                    window.location.href = "{$Think.cookie.__forward__}";
                    return true;
                });
            } else {
                layer.msg(data.info, {
                    icon: 2,
                    time: 2000 //2秒关闭（如果不配置，默认是3秒）
                });
            }
        }
    </script>
</block>